import http from "@/utils/http";

export default {
  namespaced: true,

  state: {
    homeList: [],
    color_list:{},
    download:{},
    discoloration:"",
    red_envelope:""
    
  },

  mutations: {
    SETHOMELIST(state, list) {
      state.homeList = list;
    },
    COLORLIST(state,list) {
      state.color_list = list;
    },
    REDENVELOPE(state,list) {
      state.red_envelope= list;
    },
    OPEN_MESSAGE(state,list) {
      state.download = list;
    },
    CHANGED_STATE(state,list) {
      state.discoloration = list;
    },
    COLORSTATUS(state,list){
      state.color_list=list;
    },
    HONGBAO(state,list){
      state.red_envelope= list;
    }
  },

  actions: {
    getHomeList({ commit }) {
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/login/add_balance/get_select_platform?token=${token}`
        )
        .then(response => {
          console.log("這裡啊",response);
          let res = response.data;
          console.log(res,"list");
          commit("SETHOMELIST", res);
        });
    },
    get_color({ commit}){
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/login/agent/platform_info?token=${token}`
        )
        .then(response => {
          // console.log(response,'response{');
          let redenvelope = response.data.data.red_envelope;//红包
          commit("REDENVELOPE", redenvelope);
          let color = response.data.data.lottery;//彩种
          let download = response.data.data.download;//打开信息
          commit("OPEN_MESSAGE",download)
          commit("COLORLIST", color);
        });
    },
    switch_btn({commit},{lottery,status}){
      // console.log(lottery,status,"9999");
      let token=sessionStorage.getItem('token');
      http
        .post(
          `/api/rule/lottery/platform_lottery?token=${token}`,
          {
            lottery:lottery,
            status :status
          }
        )
        .then(response => {
          // console.log(response.data.data.red_envelope, "response————————");
          let red_envelope = response.data.data.red_envelope
          let color = response.data.data.lottery;//彩种
          let status=response.data.status;
          if(status==true){
            commit("COLORSTATUS", color);
            commit("HONGBAO", red_envelope);
          }
        });
    }
  }
};
